package org.dromara.business.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.business.domain.vo.ContentReviewVo;
import org.dromara.business.domain.bo.ContentReviewBo;
import org.dromara.business.service.IContentReviewService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 统一内容审核记录
 *
 * @author Hao Tong Xue
 * @date 2025-04-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/contentReview")
public class ContentReviewController extends BaseController {

    private final IContentReviewService contentReviewService;

    /**
     * 查询统一内容审核记录列表
     */
    @SaCheckPermission("business:contentReview:list")
    @GetMapping("/list")
    public TableDataInfo<ContentReviewVo> list(ContentReviewBo bo, PageQuery pageQuery) {
        return contentReviewService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出统一内容审核记录列表
     */
    @SaCheckPermission("business:contentReview:export")
    @Log(title = "统一内容审核记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ContentReviewBo bo, HttpServletResponse response) {
        List<ContentReviewVo> list = contentReviewService.queryList(bo);
        ExcelUtil.exportExcel(list, "统一内容审核记录", ContentReviewVo.class, response);
    }

    /**
     * 获取统一内容审核记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("business:contentReview:query")
    @GetMapping("/{id}")
    public R<ContentReviewVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(contentReviewService.queryById(id));
    }

    /**
     * 新增统一内容审核记录
     */
    @SaCheckPermission("business:contentReview:add")
    @Log(title = "统一内容审核记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ContentReviewBo bo) {
        return toAjax(contentReviewService.insertByBo(bo));
    }

    /**
     * 修改统一内容审核记录
     */
    @SaCheckPermission("business:contentReview:edit")
    @Log(title = "统一内容审核记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ContentReviewBo bo) {
        return toAjax(contentReviewService.updateByBo(bo));
    }

    /**
     * 删除统一内容审核记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("business:contentReview:remove")
    @Log(title = "统一内容审核记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(contentReviewService.deleteWithValidByIds(List.of(ids), true));
    }
}
